import axios from 'axios';
/* eslint-disable */

const $api = 'http://39.107.121.254:8080/HomeworkAssistant';

function get(url, params = {}) {
	const fullUrl = $api + url;
	return new Promise((resolve, reject) => {
		axios.get(fullUrl, {
			params
		}).then(result => {
			if (result.data.statusCode === '200') {
				resolve(result.data)
			} else {
				reject(result.data)
			}
		}).catch(error => {
			reject(error);
		})
	})
}

function post(url, params = {}) {
	const fullUrl = $api + url;
	return new Promise((resolve, reject) => {
		axios.post(fullUrl, {
			params
		}).then(result => {
			if (result.data.statusCode === '200') {
				resolve(result.data)
			} else {
				console.log(result.data.message)
				reject(result.data)
			}
		}).catch(error => {
			reject(error);
		})
	})
}

function put (url, param = {}) {
  let fillUrl = $api + url
  return new Promise((resolve, reject) => {
    axios.put(fillUrl, param).then(result => {
      if (result.data.statusCode == 200) {
        resolve(result)
      } else {
        reject(result)
      }
    })
  })
}

const http = {
	get,
	post,
	put,
};

export default http
